<template>
    <view class="page-btn align-center">
        <view class="button alt loading-btn" @click="nextpage">{{ moreTxt }}</view>
    </view>
</template>

<script>
import {mapGetters} from "vuex";

export default {
    data() {
        return {
            routerPath: '',
            cid: '',
            pageNumber: 3,
            moreTxt: 'More'
        }
    },
    computed: {
        ...mapGetters(['config'])
    },
    methods: {
        nextpage() {
            if (this.moreTxt === 'Loading...') return;
            let artlsit_number = parseInt(this.config.artlsit_number)
            this.$emit('nextnewpage', (this.pageNumber += (artlsit_number || 3)));
            this.moreTxt = 'Loading...';
            if (this.routerPath.indexOf('/search') !== -1) {
                return;
            }
            uni.setStorageSync('page_number' + this.cid, this.pageNumber);
        }
    },
    mounted() {

    },
    onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
        this.cid = option.cid || option.id || '';
        let pages = getCurrentPages();
        this.routerPath = pages[pages.length - 1].route;
        if (this.routerPath.indexOf('/search') !== -1) {
            return;
        }
        this.pageNumber = parseInt(uni.getStorageSync('page_number' + this.cid)) || 3;
    }
}
</script>

<style scoped>
.loading-btn {
    border-radius: 50px;
}
.loading-btn {
    width: 50%;
}
.page-btn {
    margin-bottom: 2rem;
}
</style>
